import Vue from 'vue';

const timeupdate = {
    bind(el,config,vnode){
        let {value} = config;
        console.log("=====value",value);

        //设置播放时间
        el.currentTime = value/1000;

        el.fun = (e) => {
            vnode.context.curTime = e.target.currentTime*1000;
            vnode.context.type = 'timeupdate';
        }

        el.addEventListener('timeupdate',el.fun)
    },
    update(el,config,vnode){
        if(vnode.context.type === 'click'){
            let {value} = config;
            el.currentTime = value/1000;
        }
    },
    unbind(){
        el.removeEventListener('timeupdate',el.fun)
    }
}

//全局注册指令
Vue.directive('timeupdate',timeupdate)